package com.itheima.crm.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.itheima.crm.dao.CustomerDao;
import com.itheima.crm.pojo.Customer;
import com.itheima.crm.pojo.QueryVo;
import com.itheima.crm.service.CustomerService;
import com.itheima.crm.utils.Page;
@Service
public class CustomerServiceImpl implements CustomerService {

	@Autowired
	private CustomerDao customerDao;
	
	@Override
	public Page<Customer> getCustomerList(QueryVo queryVo) {
		//计算分页起始记录
		if (queryVo.getPage()!= null) {
			queryVo.setStart((queryVo.getPage()-1)*queryVo.getSize());
		}
		List<Customer> customerList = customerDao.getCustomerList(queryVo);
		//创建一个page
		Page<Customer> page = new Page<Customer>();
		page.setPage(queryVo.getPage());
		page.setSize(queryVo.getSize());
		page.setRows(customerList);
		Integer Count = customerDao.getCustomerCount(queryVo);
		page.setTotal(Count);
		return page;
	}

	@Override
	public Customer getCustomerById(Long id) {
		return customerDao.getCustomerById(id);
	}

	@Override
	public void getUpdateCustomer(Customer customer) {
		customerDao.getUpdateCustomer(customer);
	}

	@Override
	public void getDeleteCustomerById(Long id) {
		customerDao.getDeleteCustomerById(id);
	}

}
